package com.ludomancy.starwave;

import java.awt.Graphics;
import java.awt.Point;

import com.ludomancy.gamelib.ImageAnimation;
import com.ludomancy.gamelib.Randomizer;
import com.ludomancy.gamelib.Utils;

public class BigExplosionAnimation implements Animation
{
	private Point[] positions;
	private ImageAnimation[] anim;
	
	public BigExplosionAnimation(int x, int y)
	{
		anim = new ImageAnimation[8];
		positions = new Point[anim.length];
		for (int i = 0; i < anim.length; i++)
		{
			anim[i] = new ImageAnimation(Settings.getExplosion(-1), Randomizer.getRandom(Settings.EXPLOSION_FRAME_TIME, Settings.EXPLOSION_FRAME_TIME));
			anim[i].play();
			positions[i] = new Point();
			positions[i].x = x + Randomizer.getRandom(-12, 12);
			positions[i].y = y + Randomizer.getRandom(-12, 12);
		}
	}
	
	public void start()
	{
		
	}
	
	public void update()
	{
		for (int i = 0; i < anim.length; i++)
		{
			anim[i].update();
		}
	}
	
	public boolean isOver()
	{
		boolean over = true;
		for (int i = 0; i < anim.length; i++)
		{
			over = over && anim[i].isOver();
		}
		return over;
	}
	
	public void paint(Graphics g)
	{
		Utils.pushClipStack(g);
		g.setClip(-10, -10, 200, 200); //hack to allow explosions outside the widget
		for (int i = 0; i < anim.length; i++)
		{
			anim[i].paintCurrentFrame(g, positions[i].x, positions[i].y);
		}
		Utils.popClipStack(g);
	}
}
